#pragma once
#include <unistd.h>
#include <fcntl.h>

void SetNoBlock(int fd)
{
    int fl = fcntl(fd, F_GETFL);
    if (fl < 0)
    {
        std::cerr << "SetNoBlock() failed: " << strerror(errno) << std::endl;
        exit(1);
    }
    fcntl(fd, F_SETFL, fl | O_NONBLOCK);
}
//将拆分成功一个一个完整报文存入tokens
void SplitSegment(std::string &inbuffer, std::vector<std::string> *tokens, const std::string &sep)
{
    while (true)
    {
        auto pos = inbuffer.find(sep);
        if (pos == std::string::npos)
            break;

        std::string sub = inbuffer.substr(0, pos);
        tokens->push_back(sub);
        inbuffer.erase(0, pos + sep.size());
    }
}
bool Deserialize( std::string &seg, std::string *data1, std::string *data2) //和业务强相关的操作
{
    // 1+2
    //注意：这里就是处理了加法，乘法减法其他的都没有处理....
    std::string op = "+";
    auto pos = seg.find(op);
    if (pos == std::string::npos)
        return false;
    *data1 = seg.substr(0, pos);
    *data2 = seg.substr(pos + op.size());
    return true;
}
